#ifndef __semaphor_queue_h_
#define __semaphor_queue_h_
#include "adevs/adevs.h"
#include "io_type.h"
#include <list>
#include <sstream>

class SemaphorQueue: public adevs::Atomic<IO_Type> 
{
	public:
		/// Constructor.
		SemaphorQueue(int sn);
		/// Internal transition function.
		void delta_int();
		/// External transition function.
		void delta_ext(double e, const adevs::Bag<IO_Type>& xb);
		/// Confluent transition function.
		void delta_conf(const adevs::Bag<IO_Type>& xb);
		/// Output function.  
		void output_func(adevs::Bag<IO_Type>& yb);
		/// Time advance function.
		double ta();
		/// Output value garbage collection.
		void gc_output(adevs::Bag<IO_Type>& g);
		/// Destructor.
		~SemaphorQueue();
		/// Model input port.
		static const int in_arrive;
		static const int in_controller_cmd;
		/// Model output port.
		static const int out_depart;
		static const int out_free;
		/// Get simulation log.
		string get_log() {return sim_log.str();}
		/// Get total time of useless green.
		double get_time_useless_green() {return time_useless_green_total;}
		
	private:
		/// Which side I am
		int side_number;
		/// The clerk's clock
		double t;
		/// Simulation log storage
		stringstream sim_log;
		/// List of waiting customers.
		Vehicle* vehicle;

		SEMAPHOR_STATE semaphor_state;
		bool first_at_green;

		double time_useless_green;
		double time_useless_green_total;
};

#endif
